﻿Public Class LPItem
    Private mLevel As Integer
    Private mTextureLocked As Texture2D
    Private mTextureNormal As Texture2D
    Private mLocked As Boolean = True
    Private mCollision As Rectangle = Rectangle.Empty
    Private mFont As SpriteFont
    Private mPosition As Vector2

    Public Sub New(ByVal Level As Integer, ByRef ttNormal As Texture2D, ByRef ttLocked As Texture2D, ByRef Font As SpriteFont, ByRef SaveGame As savegame)
        mTextureLocked = ttLocked
        mTextureNormal = ttNormal
        mFont = Font
        mLevel = Level
        mPosition = New Vector2(CInt(15 + ((mLevel - 1) Mod 4) * ttLocked.Width), CInt(20 + Math.Floor((mLevel - 1) / 4) * ttLocked.Height))
        If (Level = 1 Or SaveGame.LevelUnlocked(Level)) Then
            mLocked = False
        End If
        If (Not mLocked) Then
            mCollision = New Rectangle(CInt(mPosition.X), CInt(mPosition.Y), ttLocked.Width, ttLocked.Height)
        End If
    End Sub
    Public Sub Draw(ByRef SpriteBatch As SpriteBatch)
        If (mLocked) Then
            SpriteBatch.Draw(mTextureLocked, mPosition, Color.White)
        Else
            Dim Size As Vector2 = mFont.MeasureString(mLevel.ToString)
            Dim TextPosition As Vector2 = New Vector2(CInt(mPosition.X + (mTextureLocked.Width / 2.0 - Size.X / 2.0)), mPosition.Y)
            SpriteBatch.Draw(mTextureNormal, mPosition, Color.White)
            SpriteBatch.DrawString(mFont, mLevel.ToString, New Vector2(TextPosition.X - 2, TextPosition.Y - 2), Color.Black)
            SpriteBatch.DrawString(mFont, mLevel.ToString, New Vector2(TextPosition.X - 2, TextPosition.Y + 2), Color.Black)
            SpriteBatch.DrawString(mFont, mLevel.ToString, New Vector2(TextPosition.X + 2, TextPosition.Y - 2), Color.Black)
            SpriteBatch.DrawString(mFont, mLevel.ToString, New Vector2(TextPosition.X + 2, TextPosition.Y + 2), Color.Black)
            SpriteBatch.DrawString(mFont, mLevel.ToString, TextPosition, Color.Yellow)
        End If
    End Sub
    Public Function CheckColision(ByRef TC As TouchCollection) As Boolean
        CheckColision = False
        If (mCollision <> Rectangle.Empty) Then
            For Each TouchLocation In TC
                CheckColision = CheckColision Or mCollision.Contains(CInt(TouchLocation.Position.X), CInt(TouchLocation.Position.Y))
            Next
        End If
    End Function
End Class
